package top.huxy.boot.controller.publicly;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.huxy.boot.annotation.NoRecordRequest;
import top.huxy.boot.annotation.RequestCD;
import top.huxy.boot.service.ImageService;
import top.huxy.boot.util.obj.BinaryResult;

import java.awt.image.BufferedImage;

/**
 * @author HuXY
 * @Date 2021年12月30日13:11:27
 */
@RestController
@Slf4j
public class ImageController {
    @Autowired
    ImageService imageService;


    @GetMapping(value = "/img/yzm", produces = {MediaType.IMAGE_PNG_VALUE})
    @RequestCD(time = 200, msg = "验证码冷却中")
    @NoRecordRequest
    public BufferedImage yzm() {
        return imageService.createImageYzm();
    }

    @GetMapping("/img-proxy")
    @NoRecordRequest
    public BinaryResult imgProxy(@RequestParam("url") String url) {
        return imageService.imgProxy(url);
    }
}
